// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"server/components/models/ent/forecast"
	"server/components/models/ent/predicate"
	"server/components/models/ent/region"
	"server/components/models/ent/regiontype"
	"server/components/models/ent/schema"
	"server/components/models/ent/user"
	"server/components/models/ent/weather"
	"sync"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
)

const (
	// Operation types.
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne

	// Node types.
	TypeForecast   = "Forecast"
	TypeRegion     = "Region"
	TypeRegionType = "RegionType"
	TypeUser       = "User"
	TypeWeather    = "Weather"
)

// ForecastMutation represents an operation that mutates the Forecast nodes in the graph.
type ForecastMutation struct {
	config
	op                     Op
	typ                    string
	id                     *int64
	temperature            *float64
	addtemperature         *float64
	windSpeed              *float64
	addwindSpeed           *float64
	precipitationAmount    *float64
	addprecipitationAmount *float64
	weatherCondition       *forecast.WeatherCondition
	dateTime               *time.Time
	clearedFields          map[string]struct{}
	region                 *int64
	clearedregion          bool
	regionWeather          *int64
	clearedregionWeather   bool
	done                   bool
	oldValue               func(context.Context) (*Forecast, error)
	predicates             []predicate.Forecast
}

var _ ent.Mutation = (*ForecastMutation)(nil)

// forecastOption allows management of the mutation configuration using functional options.
type forecastOption func(*ForecastMutation)

// newForecastMutation creates new mutation for the Forecast entity.
func newForecastMutation(c config, op Op, opts ...forecastOption) *ForecastMutation {
	m := &ForecastMutation{
		config:        c,
		op:            op,
		typ:           TypeForecast,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withForecastID sets the ID field of the mutation.
func withForecastID(id int64) forecastOption {
	return func(m *ForecastMutation) {
		var (
			err   error
			once  sync.Once
			value *Forecast
		)
		m.oldValue = func(ctx context.Context) (*Forecast, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Forecast.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withForecast sets the old Forecast of the mutation.
func withForecast(node *Forecast) forecastOption {
	return func(m *ForecastMutation) {
		m.oldValue = func(context.Context) (*Forecast, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m ForecastMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m ForecastMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Forecast entities.
func (m *ForecastMutation) SetID(id int64) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *ForecastMutation) ID() (id int64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *ForecastMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Forecast.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetTemperature sets the "temperature" field.
func (m *ForecastMutation) SetTemperature(f float64) {
	m.temperature = &f
	m.addtemperature = nil
}

// Temperature returns the value of the "temperature" field in the mutation.
func (m *ForecastMutation) Temperature() (r float64, exists bool) {
	v := m.temperature
	if v == nil {
		return
	}
	return *v, true
}

// OldTemperature returns the old "temperature" field's value of the Forecast entity.
// If the Forecast object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ForecastMutation) OldTemperature(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTemperature is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTemperature requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTemperature: %w", err)
	}
	return oldValue.Temperature, nil
}

// AddTemperature adds f to the "temperature" field.
func (m *ForecastMutation) AddTemperature(f float64) {
	if m.addtemperature != nil {
		*m.addtemperature += f
	} else {
		m.addtemperature = &f
	}
}

// AddedTemperature returns the value that was added to the "temperature" field in this mutation.
func (m *ForecastMutation) AddedTemperature() (r float64, exists bool) {
	v := m.addtemperature
	if v == nil {
		return
	}
	return *v, true
}

// ResetTemperature resets all changes to the "temperature" field.
func (m *ForecastMutation) ResetTemperature() {
	m.temperature = nil
	m.addtemperature = nil
}

// SetWindSpeed sets the "windSpeed" field.
func (m *ForecastMutation) SetWindSpeed(f float64) {
	m.windSpeed = &f
	m.addwindSpeed = nil
}

// WindSpeed returns the value of the "windSpeed" field in the mutation.
func (m *ForecastMutation) WindSpeed() (r float64, exists bool) {
	v := m.windSpeed
	if v == nil {
		return
	}
	return *v, true
}

// OldWindSpeed returns the old "windSpeed" field's value of the Forecast entity.
// If the Forecast object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ForecastMutation) OldWindSpeed(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWindSpeed is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWindSpeed requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWindSpeed: %w", err)
	}
	return oldValue.WindSpeed, nil
}

// AddWindSpeed adds f to the "windSpeed" field.
func (m *ForecastMutation) AddWindSpeed(f float64) {
	if m.addwindSpeed != nil {
		*m.addwindSpeed += f
	} else {
		m.addwindSpeed = &f
	}
}

// AddedWindSpeed returns the value that was added to the "windSpeed" field in this mutation.
func (m *ForecastMutation) AddedWindSpeed() (r float64, exists bool) {
	v := m.addwindSpeed
	if v == nil {
		return
	}
	return *v, true
}

// ClearWindSpeed clears the value of the "windSpeed" field.
func (m *ForecastMutation) ClearWindSpeed() {
	m.windSpeed = nil
	m.addwindSpeed = nil
	m.clearedFields[forecast.FieldWindSpeed] = struct{}{}
}

// WindSpeedCleared returns if the "windSpeed" field was cleared in this mutation.
func (m *ForecastMutation) WindSpeedCleared() bool {
	_, ok := m.clearedFields[forecast.FieldWindSpeed]
	return ok
}

// ResetWindSpeed resets all changes to the "windSpeed" field.
func (m *ForecastMutation) ResetWindSpeed() {
	m.windSpeed = nil
	m.addwindSpeed = nil
	delete(m.clearedFields, forecast.FieldWindSpeed)
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (m *ForecastMutation) SetPrecipitationAmount(f float64) {
	m.precipitationAmount = &f
	m.addprecipitationAmount = nil
}

// PrecipitationAmount returns the value of the "precipitationAmount" field in the mutation.
func (m *ForecastMutation) PrecipitationAmount() (r float64, exists bool) {
	v := m.precipitationAmount
	if v == nil {
		return
	}
	return *v, true
}

// OldPrecipitationAmount returns the old "precipitationAmount" field's value of the Forecast entity.
// If the Forecast object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ForecastMutation) OldPrecipitationAmount(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPrecipitationAmount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPrecipitationAmount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPrecipitationAmount: %w", err)
	}
	return oldValue.PrecipitationAmount, nil
}

// AddPrecipitationAmount adds f to the "precipitationAmount" field.
func (m *ForecastMutation) AddPrecipitationAmount(f float64) {
	if m.addprecipitationAmount != nil {
		*m.addprecipitationAmount += f
	} else {
		m.addprecipitationAmount = &f
	}
}

// AddedPrecipitationAmount returns the value that was added to the "precipitationAmount" field in this mutation.
func (m *ForecastMutation) AddedPrecipitationAmount() (r float64, exists bool) {
	v := m.addprecipitationAmount
	if v == nil {
		return
	}
	return *v, true
}

// ClearPrecipitationAmount clears the value of the "precipitationAmount" field.
func (m *ForecastMutation) ClearPrecipitationAmount() {
	m.precipitationAmount = nil
	m.addprecipitationAmount = nil
	m.clearedFields[forecast.FieldPrecipitationAmount] = struct{}{}
}

// PrecipitationAmountCleared returns if the "precipitationAmount" field was cleared in this mutation.
func (m *ForecastMutation) PrecipitationAmountCleared() bool {
	_, ok := m.clearedFields[forecast.FieldPrecipitationAmount]
	return ok
}

// ResetPrecipitationAmount resets all changes to the "precipitationAmount" field.
func (m *ForecastMutation) ResetPrecipitationAmount() {
	m.precipitationAmount = nil
	m.addprecipitationAmount = nil
	delete(m.clearedFields, forecast.FieldPrecipitationAmount)
}

// SetWeatherCondition sets the "weatherCondition" field.
func (m *ForecastMutation) SetWeatherCondition(fc forecast.WeatherCondition) {
	m.weatherCondition = &fc
}

// WeatherCondition returns the value of the "weatherCondition" field in the mutation.
func (m *ForecastMutation) WeatherCondition() (r forecast.WeatherCondition, exists bool) {
	v := m.weatherCondition
	if v == nil {
		return
	}
	return *v, true
}

// OldWeatherCondition returns the old "weatherCondition" field's value of the Forecast entity.
// If the Forecast object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ForecastMutation) OldWeatherCondition(ctx context.Context) (v forecast.WeatherCondition, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWeatherCondition is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWeatherCondition requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWeatherCondition: %w", err)
	}
	return oldValue.WeatherCondition, nil
}

// ResetWeatherCondition resets all changes to the "weatherCondition" field.
func (m *ForecastMutation) ResetWeatherCondition() {
	m.weatherCondition = nil
}

// SetDateTime sets the "dateTime" field.
func (m *ForecastMutation) SetDateTime(t time.Time) {
	m.dateTime = &t
}

// DateTime returns the value of the "dateTime" field in the mutation.
func (m *ForecastMutation) DateTime() (r time.Time, exists bool) {
	v := m.dateTime
	if v == nil {
		return
	}
	return *v, true
}

// OldDateTime returns the old "dateTime" field's value of the Forecast entity.
// If the Forecast object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ForecastMutation) OldDateTime(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDateTime is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDateTime requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDateTime: %w", err)
	}
	return oldValue.DateTime, nil
}

// ResetDateTime resets all changes to the "dateTime" field.
func (m *ForecastMutation) ResetDateTime() {
	m.dateTime = nil
}

// SetRegionID sets the "region" edge to the Region entity by id.
func (m *ForecastMutation) SetRegionID(id int64) {
	m.region = &id
}

// ClearRegion clears the "region" edge to the Region entity.
func (m *ForecastMutation) ClearRegion() {
	m.clearedregion = true
}

// RegionCleared reports if the "region" edge to the Region entity was cleared.
func (m *ForecastMutation) RegionCleared() bool {
	return m.clearedregion
}

// RegionID returns the "region" edge ID in the mutation.
func (m *ForecastMutation) RegionID() (id int64, exists bool) {
	if m.region != nil {
		return *m.region, true
	}
	return
}

// RegionIDs returns the "region" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// RegionID instead. It exists only for internal usage by the builders.
func (m *ForecastMutation) RegionIDs() (ids []int64) {
	if id := m.region; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetRegion resets all changes to the "region" edge.
func (m *ForecastMutation) ResetRegion() {
	m.region = nil
	m.clearedregion = false
}

// SetRegionWeatherID sets the "regionWeather" edge to the Weather entity by id.
func (m *ForecastMutation) SetRegionWeatherID(id int64) {
	m.regionWeather = &id
}

// ClearRegionWeather clears the "regionWeather" edge to the Weather entity.
func (m *ForecastMutation) ClearRegionWeather() {
	m.clearedregionWeather = true
}

// RegionWeatherCleared reports if the "regionWeather" edge to the Weather entity was cleared.
func (m *ForecastMutation) RegionWeatherCleared() bool {
	return m.clearedregionWeather
}

// RegionWeatherID returns the "regionWeather" edge ID in the mutation.
func (m *ForecastMutation) RegionWeatherID() (id int64, exists bool) {
	if m.regionWeather != nil {
		return *m.regionWeather, true
	}
	return
}

// RegionWeatherIDs returns the "regionWeather" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// RegionWeatherID instead. It exists only for internal usage by the builders.
func (m *ForecastMutation) RegionWeatherIDs() (ids []int64) {
	if id := m.regionWeather; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetRegionWeather resets all changes to the "regionWeather" edge.
func (m *ForecastMutation) ResetRegionWeather() {
	m.regionWeather = nil
	m.clearedregionWeather = false
}

// Where appends a list predicates to the ForecastMutation builder.
func (m *ForecastMutation) Where(ps ...predicate.Forecast) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the ForecastMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *ForecastMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.Forecast, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *ForecastMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *ForecastMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (Forecast).
func (m *ForecastMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *ForecastMutation) Fields() []string {
	fields := make([]string, 0, 5)
	if m.temperature != nil {
		fields = append(fields, forecast.FieldTemperature)
	}
	if m.windSpeed != nil {
		fields = append(fields, forecast.FieldWindSpeed)
	}
	if m.precipitationAmount != nil {
		fields = append(fields, forecast.FieldPrecipitationAmount)
	}
	if m.weatherCondition != nil {
		fields = append(fields, forecast.FieldWeatherCondition)
	}
	if m.dateTime != nil {
		fields = append(fields, forecast.FieldDateTime)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *ForecastMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case forecast.FieldTemperature:
		return m.Temperature()
	case forecast.FieldWindSpeed:
		return m.WindSpeed()
	case forecast.FieldPrecipitationAmount:
		return m.PrecipitationAmount()
	case forecast.FieldWeatherCondition:
		return m.WeatherCondition()
	case forecast.FieldDateTime:
		return m.DateTime()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *ForecastMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case forecast.FieldTemperature:
		return m.OldTemperature(ctx)
	case forecast.FieldWindSpeed:
		return m.OldWindSpeed(ctx)
	case forecast.FieldPrecipitationAmount:
		return m.OldPrecipitationAmount(ctx)
	case forecast.FieldWeatherCondition:
		return m.OldWeatherCondition(ctx)
	case forecast.FieldDateTime:
		return m.OldDateTime(ctx)
	}
	return nil, fmt.Errorf("unknown Forecast field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *ForecastMutation) SetField(name string, value ent.Value) error {
	switch name {
	case forecast.FieldTemperature:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTemperature(v)
		return nil
	case forecast.FieldWindSpeed:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWindSpeed(v)
		return nil
	case forecast.FieldPrecipitationAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPrecipitationAmount(v)
		return nil
	case forecast.FieldWeatherCondition:
		v, ok := value.(forecast.WeatherCondition)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWeatherCondition(v)
		return nil
	case forecast.FieldDateTime:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDateTime(v)
		return nil
	}
	return fmt.Errorf("unknown Forecast field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *ForecastMutation) AddedFields() []string {
	var fields []string
	if m.addtemperature != nil {
		fields = append(fields, forecast.FieldTemperature)
	}
	if m.addwindSpeed != nil {
		fields = append(fields, forecast.FieldWindSpeed)
	}
	if m.addprecipitationAmount != nil {
		fields = append(fields, forecast.FieldPrecipitationAmount)
	}
	return fields
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *ForecastMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case forecast.FieldTemperature:
		return m.AddedTemperature()
	case forecast.FieldWindSpeed:
		return m.AddedWindSpeed()
	case forecast.FieldPrecipitationAmount:
		return m.AddedPrecipitationAmount()
	}
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *ForecastMutation) AddField(name string, value ent.Value) error {
	switch name {
	case forecast.FieldTemperature:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddTemperature(v)
		return nil
	case forecast.FieldWindSpeed:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddWindSpeed(v)
		return nil
	case forecast.FieldPrecipitationAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPrecipitationAmount(v)
		return nil
	}
	return fmt.Errorf("unknown Forecast numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *ForecastMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(forecast.FieldWindSpeed) {
		fields = append(fields, forecast.FieldWindSpeed)
	}
	if m.FieldCleared(forecast.FieldPrecipitationAmount) {
		fields = append(fields, forecast.FieldPrecipitationAmount)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ForecastMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *ForecastMutation) ClearField(name string) error {
	switch name {
	case forecast.FieldWindSpeed:
		m.ClearWindSpeed()
		return nil
	case forecast.FieldPrecipitationAmount:
		m.ClearPrecipitationAmount()
		return nil
	}
	return fmt.Errorf("unknown Forecast nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *ForecastMutation) ResetField(name string) error {
	switch name {
	case forecast.FieldTemperature:
		m.ResetTemperature()
		return nil
	case forecast.FieldWindSpeed:
		m.ResetWindSpeed()
		return nil
	case forecast.FieldPrecipitationAmount:
		m.ResetPrecipitationAmount()
		return nil
	case forecast.FieldWeatherCondition:
		m.ResetWeatherCondition()
		return nil
	case forecast.FieldDateTime:
		m.ResetDateTime()
		return nil
	}
	return fmt.Errorf("unknown Forecast field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ForecastMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.region != nil {
		edges = append(edges, forecast.EdgeRegion)
	}
	if m.regionWeather != nil {
		edges = append(edges, forecast.EdgeRegionWeather)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *ForecastMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case forecast.EdgeRegion:
		if id := m.region; id != nil {
			return []ent.Value{*id}
		}
	case forecast.EdgeRegionWeather:
		if id := m.regionWeather; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ForecastMutation) RemovedEdges() []string {
	edges := make([]string, 0, 2)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *ForecastMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ForecastMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedregion {
		edges = append(edges, forecast.EdgeRegion)
	}
	if m.clearedregionWeather {
		edges = append(edges, forecast.EdgeRegionWeather)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ForecastMutation) EdgeCleared(name string) bool {
	switch name {
	case forecast.EdgeRegion:
		return m.clearedregion
	case forecast.EdgeRegionWeather:
		return m.clearedregionWeather
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *ForecastMutation) ClearEdge(name string) error {
	switch name {
	case forecast.EdgeRegion:
		m.ClearRegion()
		return nil
	case forecast.EdgeRegionWeather:
		m.ClearRegionWeather()
		return nil
	}
	return fmt.Errorf("unknown Forecast unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *ForecastMutation) ResetEdge(name string) error {
	switch name {
	case forecast.EdgeRegion:
		m.ResetRegion()
		return nil
	case forecast.EdgeRegionWeather:
		m.ResetRegionWeather()
		return nil
	}
	return fmt.Errorf("unknown Forecast edge %s", name)
}

// RegionMutation represents an operation that mutates the Region nodes in the graph.
type RegionMutation struct {
	config
	op                Op
	typ               string
	id                *int64
	name              *string
	parentRegion      *string
	latitude1         *float64
	addlatitude1      *float64
	longitude1        *float64
	addlongitude1     *float64
	latitude2         *float64
	addlatitude2      *float64
	longitude2        *float64
	addlongitude2     *float64
	osmData           *schema.OsmData
	clearedFields     map[string]struct{}
	regionType        *int64
	clearedregionType bool
	accountId         *int
	clearedaccountId  bool
	done              bool
	oldValue          func(context.Context) (*Region, error)
	predicates        []predicate.Region
}

var _ ent.Mutation = (*RegionMutation)(nil)

// regionOption allows management of the mutation configuration using functional options.
type regionOption func(*RegionMutation)

// newRegionMutation creates new mutation for the Region entity.
func newRegionMutation(c config, op Op, opts ...regionOption) *RegionMutation {
	m := &RegionMutation{
		config:        c,
		op:            op,
		typ:           TypeRegion,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withRegionID sets the ID field of the mutation.
func withRegionID(id int64) regionOption {
	return func(m *RegionMutation) {
		var (
			err   error
			once  sync.Once
			value *Region
		)
		m.oldValue = func(ctx context.Context) (*Region, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Region.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withRegion sets the old Region of the mutation.
func withRegion(node *Region) regionOption {
	return func(m *RegionMutation) {
		m.oldValue = func(context.Context) (*Region, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m RegionMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m RegionMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Region entities.
func (m *RegionMutation) SetID(id int64) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *RegionMutation) ID() (id int64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *RegionMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Region.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetName sets the "name" field.
func (m *RegionMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *RegionMutation) Name() (r string, exists bool) {
	v := m.name
	if v == nil {
		return
	}
	return *v, true
}

// OldName returns the old "name" field's value of the Region entity.
// If the Region object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RegionMutation) OldName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldName: %w", err)
	}
	return oldValue.Name, nil
}

// ResetName resets all changes to the "name" field.
func (m *RegionMutation) ResetName() {
	m.name = nil
}

// SetParentRegion sets the "parentRegion" field.
func (m *RegionMutation) SetParentRegion(s string) {
	m.parentRegion = &s
}

// ParentRegion returns the value of the "parentRegion" field in the mutation.
func (m *RegionMutation) ParentRegion() (r string, exists bool) {
	v := m.parentRegion
	if v == nil {
		return
	}
	return *v, true
}

// OldParentRegion returns the old "parentRegion" field's value of the Region entity.
// If the Region object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RegionMutation) OldParentRegion(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldParentRegion is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldParentRegion requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldParentRegion: %w", err)
	}
	return oldValue.ParentRegion, nil
}

// ClearParentRegion clears the value of the "parentRegion" field.
func (m *RegionMutation) ClearParentRegion() {
	m.parentRegion = nil
	m.clearedFields[region.FieldParentRegion] = struct{}{}
}

// ParentRegionCleared returns if the "parentRegion" field was cleared in this mutation.
func (m *RegionMutation) ParentRegionCleared() bool {
	_, ok := m.clearedFields[region.FieldParentRegion]
	return ok
}

// ResetParentRegion resets all changes to the "parentRegion" field.
func (m *RegionMutation) ResetParentRegion() {
	m.parentRegion = nil
	delete(m.clearedFields, region.FieldParentRegion)
}

// SetLatitude1 sets the "latitude1" field.
func (m *RegionMutation) SetLatitude1(f float64) {
	m.latitude1 = &f
	m.addlatitude1 = nil
}

// Latitude1 returns the value of the "latitude1" field in the mutation.
func (m *RegionMutation) Latitude1() (r float64, exists bool) {
	v := m.latitude1
	if v == nil {
		return
	}
	return *v, true
}

// OldLatitude1 returns the old "latitude1" field's value of the Region entity.
// If the Region object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RegionMutation) OldLatitude1(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLatitude1 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLatitude1 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLatitude1: %w", err)
	}
	return oldValue.Latitude1, nil
}

// AddLatitude1 adds f to the "latitude1" field.
func (m *RegionMutation) AddLatitude1(f float64) {
	if m.addlatitude1 != nil {
		*m.addlatitude1 += f
	} else {
		m.addlatitude1 = &f
	}
}

// AddedLatitude1 returns the value that was added to the "latitude1" field in this mutation.
func (m *RegionMutation) AddedLatitude1() (r float64, exists bool) {
	v := m.addlatitude1
	if v == nil {
		return
	}
	return *v, true
}

// ClearLatitude1 clears the value of the "latitude1" field.
func (m *RegionMutation) ClearLatitude1() {
	m.latitude1 = nil
	m.addlatitude1 = nil
	m.clearedFields[region.FieldLatitude1] = struct{}{}
}

// Latitude1Cleared returns if the "latitude1" field was cleared in this mutation.
func (m *RegionMutation) Latitude1Cleared() bool {
	_, ok := m.clearedFields[region.FieldLatitude1]
	return ok
}

// ResetLatitude1 resets all changes to the "latitude1" field.
func (m *RegionMutation) ResetLatitude1() {
	m.latitude1 = nil
	m.addlatitude1 = nil
	delete(m.clearedFields, region.FieldLatitude1)
}

// SetLongitude1 sets the "longitude1" field.
func (m *RegionMutation) SetLongitude1(f float64) {
	m.longitude1 = &f
	m.addlongitude1 = nil
}

// Longitude1 returns the value of the "longitude1" field in the mutation.
func (m *RegionMutation) Longitude1() (r float64, exists bool) {
	v := m.longitude1
	if v == nil {
		return
	}
	return *v, true
}

// OldLongitude1 returns the old "longitude1" field's value of the Region entity.
// If the Region object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RegionMutation) OldLongitude1(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLongitude1 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLongitude1 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLongitude1: %w", err)
	}
	return oldValue.Longitude1, nil
}

// AddLongitude1 adds f to the "longitude1" field.
func (m *RegionMutation) AddLongitude1(f float64) {
	if m.addlongitude1 != nil {
		*m.addlongitude1 += f
	} else {
		m.addlongitude1 = &f
	}
}

// AddedLongitude1 returns the value that was added to the "longitude1" field in this mutation.
func (m *RegionMutation) AddedLongitude1() (r float64, exists bool) {
	v := m.addlongitude1
	if v == nil {
		return
	}
	return *v, true
}

// ClearLongitude1 clears the value of the "longitude1" field.
func (m *RegionMutation) ClearLongitude1() {
	m.longitude1 = nil
	m.addlongitude1 = nil
	m.clearedFields[region.FieldLongitude1] = struct{}{}
}

// Longitude1Cleared returns if the "longitude1" field was cleared in this mutation.
func (m *RegionMutation) Longitude1Cleared() bool {
	_, ok := m.clearedFields[region.FieldLongitude1]
	return ok
}

// ResetLongitude1 resets all changes to the "longitude1" field.
func (m *RegionMutation) ResetLongitude1() {
	m.longitude1 = nil
	m.addlongitude1 = nil
	delete(m.clearedFields, region.FieldLongitude1)
}

// SetLatitude2 sets the "latitude2" field.
func (m *RegionMutation) SetLatitude2(f float64) {
	m.latitude2 = &f
	m.addlatitude2 = nil
}

// Latitude2 returns the value of the "latitude2" field in the mutation.
func (m *RegionMutation) Latitude2() (r float64, exists bool) {
	v := m.latitude2
	if v == nil {
		return
	}
	return *v, true
}

// OldLatitude2 returns the old "latitude2" field's value of the Region entity.
// If the Region object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RegionMutation) OldLatitude2(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLatitude2 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLatitude2 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLatitude2: %w", err)
	}
	return oldValue.Latitude2, nil
}

// AddLatitude2 adds f to the "latitude2" field.
func (m *RegionMutation) AddLatitude2(f float64) {
	if m.addlatitude2 != nil {
		*m.addlatitude2 += f
	} else {
		m.addlatitude2 = &f
	}
}

// AddedLatitude2 returns the value that was added to the "latitude2" field in this mutation.
func (m *RegionMutation) AddedLatitude2() (r float64, exists bool) {
	v := m.addlatitude2
	if v == nil {
		return
	}
	return *v, true
}

// ClearLatitude2 clears the value of the "latitude2" field.
func (m *RegionMutation) ClearLatitude2() {
	m.latitude2 = nil
	m.addlatitude2 = nil
	m.clearedFields[region.FieldLatitude2] = struct{}{}
}

// Latitude2Cleared returns if the "latitude2" field was cleared in this mutation.
func (m *RegionMutation) Latitude2Cleared() bool {
	_, ok := m.clearedFields[region.FieldLatitude2]
	return ok
}

// ResetLatitude2 resets all changes to the "latitude2" field.
func (m *RegionMutation) ResetLatitude2() {
	m.latitude2 = nil
	m.addlatitude2 = nil
	delete(m.clearedFields, region.FieldLatitude2)
}

// SetLongitude2 sets the "longitude2" field.
func (m *RegionMutation) SetLongitude2(f float64) {
	m.longitude2 = &f
	m.addlongitude2 = nil
}

// Longitude2 returns the value of the "longitude2" field in the mutation.
func (m *RegionMutation) Longitude2() (r float64, exists bool) {
	v := m.longitude2
	if v == nil {
		return
	}
	return *v, true
}

// OldLongitude2 returns the old "longitude2" field's value of the Region entity.
// If the Region object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RegionMutation) OldLongitude2(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLongitude2 is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLongitude2 requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLongitude2: %w", err)
	}
	return oldValue.Longitude2, nil
}

// AddLongitude2 adds f to the "longitude2" field.
func (m *RegionMutation) AddLongitude2(f float64) {
	if m.addlongitude2 != nil {
		*m.addlongitude2 += f
	} else {
		m.addlongitude2 = &f
	}
}

// AddedLongitude2 returns the value that was added to the "longitude2" field in this mutation.
func (m *RegionMutation) AddedLongitude2() (r float64, exists bool) {
	v := m.addlongitude2
	if v == nil {
		return
	}
	return *v, true
}

// ClearLongitude2 clears the value of the "longitude2" field.
func (m *RegionMutation) ClearLongitude2() {
	m.longitude2 = nil
	m.addlongitude2 = nil
	m.clearedFields[region.FieldLongitude2] = struct{}{}
}

// Longitude2Cleared returns if the "longitude2" field was cleared in this mutation.
func (m *RegionMutation) Longitude2Cleared() bool {
	_, ok := m.clearedFields[region.FieldLongitude2]
	return ok
}

// ResetLongitude2 resets all changes to the "longitude2" field.
func (m *RegionMutation) ResetLongitude2() {
	m.longitude2 = nil
	m.addlongitude2 = nil
	delete(m.clearedFields, region.FieldLongitude2)
}

// SetOsmData sets the "osmData" field.
func (m *RegionMutation) SetOsmData(sd schema.OsmData) {
	m.osmData = &sd
}

// OsmData returns the value of the "osmData" field in the mutation.
func (m *RegionMutation) OsmData() (r schema.OsmData, exists bool) {
	v := m.osmData
	if v == nil {
		return
	}
	return *v, true
}

// OldOsmData returns the old "osmData" field's value of the Region entity.
// If the Region object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RegionMutation) OldOsmData(ctx context.Context) (v schema.OsmData, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldOsmData is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldOsmData requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldOsmData: %w", err)
	}
	return oldValue.OsmData, nil
}

// ClearOsmData clears the value of the "osmData" field.
func (m *RegionMutation) ClearOsmData() {
	m.osmData = nil
	m.clearedFields[region.FieldOsmData] = struct{}{}
}

// OsmDataCleared returns if the "osmData" field was cleared in this mutation.
func (m *RegionMutation) OsmDataCleared() bool {
	_, ok := m.clearedFields[region.FieldOsmData]
	return ok
}

// ResetOsmData resets all changes to the "osmData" field.
func (m *RegionMutation) ResetOsmData() {
	m.osmData = nil
	delete(m.clearedFields, region.FieldOsmData)
}

// SetRegionTypeID sets the "regionType" edge to the RegionType entity by id.
func (m *RegionMutation) SetRegionTypeID(id int64) {
	m.regionType = &id
}

// ClearRegionType clears the "regionType" edge to the RegionType entity.
func (m *RegionMutation) ClearRegionType() {
	m.clearedregionType = true
}

// RegionTypeCleared reports if the "regionType" edge to the RegionType entity was cleared.
func (m *RegionMutation) RegionTypeCleared() bool {
	return m.clearedregionType
}

// RegionTypeID returns the "regionType" edge ID in the mutation.
func (m *RegionMutation) RegionTypeID() (id int64, exists bool) {
	if m.regionType != nil {
		return *m.regionType, true
	}
	return
}

// RegionTypeIDs returns the "regionType" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// RegionTypeID instead. It exists only for internal usage by the builders.
func (m *RegionMutation) RegionTypeIDs() (ids []int64) {
	if id := m.regionType; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetRegionType resets all changes to the "regionType" edge.
func (m *RegionMutation) ResetRegionType() {
	m.regionType = nil
	m.clearedregionType = false
}

// SetAccountIdID sets the "accountId" edge to the User entity by id.
func (m *RegionMutation) SetAccountIdID(id int) {
	m.accountId = &id
}

// ClearAccountId clears the "accountId" edge to the User entity.
func (m *RegionMutation) ClearAccountId() {
	m.clearedaccountId = true
}

// AccountIdCleared reports if the "accountId" edge to the User entity was cleared.
func (m *RegionMutation) AccountIdCleared() bool {
	return m.clearedaccountId
}

// AccountIdID returns the "accountId" edge ID in the mutation.
func (m *RegionMutation) AccountIdID() (id int, exists bool) {
	if m.accountId != nil {
		return *m.accountId, true
	}
	return
}

// AccountIdIDs returns the "accountId" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// AccountIdID instead. It exists only for internal usage by the builders.
func (m *RegionMutation) AccountIdIDs() (ids []int) {
	if id := m.accountId; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetAccountId resets all changes to the "accountId" edge.
func (m *RegionMutation) ResetAccountId() {
	m.accountId = nil
	m.clearedaccountId = false
}

// Where appends a list predicates to the RegionMutation builder.
func (m *RegionMutation) Where(ps ...predicate.Region) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the RegionMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *RegionMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.Region, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *RegionMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *RegionMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (Region).
func (m *RegionMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *RegionMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.name != nil {
		fields = append(fields, region.FieldName)
	}
	if m.parentRegion != nil {
		fields = append(fields, region.FieldParentRegion)
	}
	if m.latitude1 != nil {
		fields = append(fields, region.FieldLatitude1)
	}
	if m.longitude1 != nil {
		fields = append(fields, region.FieldLongitude1)
	}
	if m.latitude2 != nil {
		fields = append(fields, region.FieldLatitude2)
	}
	if m.longitude2 != nil {
		fields = append(fields, region.FieldLongitude2)
	}
	if m.osmData != nil {
		fields = append(fields, region.FieldOsmData)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *RegionMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case region.FieldName:
		return m.Name()
	case region.FieldParentRegion:
		return m.ParentRegion()
	case region.FieldLatitude1:
		return m.Latitude1()
	case region.FieldLongitude1:
		return m.Longitude1()
	case region.FieldLatitude2:
		return m.Latitude2()
	case region.FieldLongitude2:
		return m.Longitude2()
	case region.FieldOsmData:
		return m.OsmData()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *RegionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case region.FieldName:
		return m.OldName(ctx)
	case region.FieldParentRegion:
		return m.OldParentRegion(ctx)
	case region.FieldLatitude1:
		return m.OldLatitude1(ctx)
	case region.FieldLongitude1:
		return m.OldLongitude1(ctx)
	case region.FieldLatitude2:
		return m.OldLatitude2(ctx)
	case region.FieldLongitude2:
		return m.OldLongitude2(ctx)
	case region.FieldOsmData:
		return m.OldOsmData(ctx)
	}
	return nil, fmt.Errorf("unknown Region field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *RegionMutation) SetField(name string, value ent.Value) error {
	switch name {
	case region.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case region.FieldParentRegion:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetParentRegion(v)
		return nil
	case region.FieldLatitude1:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLatitude1(v)
		return nil
	case region.FieldLongitude1:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLongitude1(v)
		return nil
	case region.FieldLatitude2:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLatitude2(v)
		return nil
	case region.FieldLongitude2:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLongitude2(v)
		return nil
	case region.FieldOsmData:
		v, ok := value.(schema.OsmData)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOsmData(v)
		return nil
	}
	return fmt.Errorf("unknown Region field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *RegionMutation) AddedFields() []string {
	var fields []string
	if m.addlatitude1 != nil {
		fields = append(fields, region.FieldLatitude1)
	}
	if m.addlongitude1 != nil {
		fields = append(fields, region.FieldLongitude1)
	}
	if m.addlatitude2 != nil {
		fields = append(fields, region.FieldLatitude2)
	}
	if m.addlongitude2 != nil {
		fields = append(fields, region.FieldLongitude2)
	}
	return fields
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *RegionMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case region.FieldLatitude1:
		return m.AddedLatitude1()
	case region.FieldLongitude1:
		return m.AddedLongitude1()
	case region.FieldLatitude2:
		return m.AddedLatitude2()
	case region.FieldLongitude2:
		return m.AddedLongitude2()
	}
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *RegionMutation) AddField(name string, value ent.Value) error {
	switch name {
	case region.FieldLatitude1:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddLatitude1(v)
		return nil
	case region.FieldLongitude1:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddLongitude1(v)
		return nil
	case region.FieldLatitude2:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddLatitude2(v)
		return nil
	case region.FieldLongitude2:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddLongitude2(v)
		return nil
	}
	return fmt.Errorf("unknown Region numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *RegionMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(region.FieldParentRegion) {
		fields = append(fields, region.FieldParentRegion)
	}
	if m.FieldCleared(region.FieldLatitude1) {
		fields = append(fields, region.FieldLatitude1)
	}
	if m.FieldCleared(region.FieldLongitude1) {
		fields = append(fields, region.FieldLongitude1)
	}
	if m.FieldCleared(region.FieldLatitude2) {
		fields = append(fields, region.FieldLatitude2)
	}
	if m.FieldCleared(region.FieldLongitude2) {
		fields = append(fields, region.FieldLongitude2)
	}
	if m.FieldCleared(region.FieldOsmData) {
		fields = append(fields, region.FieldOsmData)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *RegionMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *RegionMutation) ClearField(name string) error {
	switch name {
	case region.FieldParentRegion:
		m.ClearParentRegion()
		return nil
	case region.FieldLatitude1:
		m.ClearLatitude1()
		return nil
	case region.FieldLongitude1:
		m.ClearLongitude1()
		return nil
	case region.FieldLatitude2:
		m.ClearLatitude2()
		return nil
	case region.FieldLongitude2:
		m.ClearLongitude2()
		return nil
	case region.FieldOsmData:
		m.ClearOsmData()
		return nil
	}
	return fmt.Errorf("unknown Region nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *RegionMutation) ResetField(name string) error {
	switch name {
	case region.FieldName:
		m.ResetName()
		return nil
	case region.FieldParentRegion:
		m.ResetParentRegion()
		return nil
	case region.FieldLatitude1:
		m.ResetLatitude1()
		return nil
	case region.FieldLongitude1:
		m.ResetLongitude1()
		return nil
	case region.FieldLatitude2:
		m.ResetLatitude2()
		return nil
	case region.FieldLongitude2:
		m.ResetLongitude2()
		return nil
	case region.FieldOsmData:
		m.ResetOsmData()
		return nil
	}
	return fmt.Errorf("unknown Region field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *RegionMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.regionType != nil {
		edges = append(edges, region.EdgeRegionType)
	}
	if m.accountId != nil {
		edges = append(edges, region.EdgeAccountId)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *RegionMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case region.EdgeRegionType:
		if id := m.regionType; id != nil {
			return []ent.Value{*id}
		}
	case region.EdgeAccountId:
		if id := m.accountId; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *RegionMutation) RemovedEdges() []string {
	edges := make([]string, 0, 2)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *RegionMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *RegionMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedregionType {
		edges = append(edges, region.EdgeRegionType)
	}
	if m.clearedaccountId {
		edges = append(edges, region.EdgeAccountId)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *RegionMutation) EdgeCleared(name string) bool {
	switch name {
	case region.EdgeRegionType:
		return m.clearedregionType
	case region.EdgeAccountId:
		return m.clearedaccountId
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *RegionMutation) ClearEdge(name string) error {
	switch name {
	case region.EdgeRegionType:
		m.ClearRegionType()
		return nil
	case region.EdgeAccountId:
		m.ClearAccountId()
		return nil
	}
	return fmt.Errorf("unknown Region unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *RegionMutation) ResetEdge(name string) error {
	switch name {
	case region.EdgeRegionType:
		m.ResetRegionType()
		return nil
	case region.EdgeAccountId:
		m.ResetAccountId()
		return nil
	}
	return fmt.Errorf("unknown Region edge %s", name)
}

// RegionTypeMutation represents an operation that mutates the RegionType nodes in the graph.
type RegionTypeMutation struct {
	config
	op            Op
	typ           string
	id            *int64
	_type         *string
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*RegionType, error)
	predicates    []predicate.RegionType
}

var _ ent.Mutation = (*RegionTypeMutation)(nil)

// regiontypeOption allows management of the mutation configuration using functional options.
type regiontypeOption func(*RegionTypeMutation)

// newRegionTypeMutation creates new mutation for the RegionType entity.
func newRegionTypeMutation(c config, op Op, opts ...regiontypeOption) *RegionTypeMutation {
	m := &RegionTypeMutation{
		config:        c,
		op:            op,
		typ:           TypeRegionType,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withRegionTypeID sets the ID field of the mutation.
func withRegionTypeID(id int64) regiontypeOption {
	return func(m *RegionTypeMutation) {
		var (
			err   error
			once  sync.Once
			value *RegionType
		)
		m.oldValue = func(ctx context.Context) (*RegionType, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().RegionType.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withRegionType sets the old RegionType of the mutation.
func withRegionType(node *RegionType) regiontypeOption {
	return func(m *RegionTypeMutation) {
		m.oldValue = func(context.Context) (*RegionType, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m RegionTypeMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m RegionTypeMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of RegionType entities.
func (m *RegionTypeMutation) SetID(id int64) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *RegionTypeMutation) ID() (id int64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *RegionTypeMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().RegionType.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetType sets the "type" field.
func (m *RegionTypeMutation) SetType(s string) {
	m._type = &s
}

// GetType returns the value of the "type" field in the mutation.
func (m *RegionTypeMutation) GetType() (r string, exists bool) {
	v := m._type
	if v == nil {
		return
	}
	return *v, true
}

// OldType returns the old "type" field's value of the RegionType entity.
// If the RegionType object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RegionTypeMutation) OldType(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldType: %w", err)
	}
	return oldValue.Type, nil
}

// ResetType resets all changes to the "type" field.
func (m *RegionTypeMutation) ResetType() {
	m._type = nil
}

// Where appends a list predicates to the RegionTypeMutation builder.
func (m *RegionTypeMutation) Where(ps ...predicate.RegionType) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the RegionTypeMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *RegionTypeMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.RegionType, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *RegionTypeMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *RegionTypeMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (RegionType).
func (m *RegionTypeMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *RegionTypeMutation) Fields() []string {
	fields := make([]string, 0, 1)
	if m._type != nil {
		fields = append(fields, regiontype.FieldType)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *RegionTypeMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case regiontype.FieldType:
		return m.GetType()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *RegionTypeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case regiontype.FieldType:
		return m.OldType(ctx)
	}
	return nil, fmt.Errorf("unknown RegionType field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *RegionTypeMutation) SetField(name string, value ent.Value) error {
	switch name {
	case regiontype.FieldType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetType(v)
		return nil
	}
	return fmt.Errorf("unknown RegionType field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *RegionTypeMutation) AddedFields() []string {
	return nil
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *RegionTypeMutation) AddedField(name string) (ent.Value, bool) {
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *RegionTypeMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown RegionType numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *RegionTypeMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *RegionTypeMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *RegionTypeMutation) ClearField(name string) error {
	return fmt.Errorf("unknown RegionType nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *RegionTypeMutation) ResetField(name string) error {
	switch name {
	case regiontype.FieldType:
		m.ResetType()
		return nil
	}
	return fmt.Errorf("unknown RegionType field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *RegionTypeMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *RegionTypeMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *RegionTypeMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *RegionTypeMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *RegionTypeMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *RegionTypeMutation) EdgeCleared(name string) bool {
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *RegionTypeMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown RegionType unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *RegionTypeMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown RegionType edge %s", name)
}

// UserMutation represents an operation that mutates the User nodes in the graph.
type UserMutation struct {
	config
	op            Op
	typ           string
	id            *int
	email         *string
	password      *[]byte
	firstName     *string
	lastName      *string
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*User, error)
	predicates    []predicate.User
}

var _ ent.Mutation = (*UserMutation)(nil)

// userOption allows management of the mutation configuration using functional options.
type userOption func(*UserMutation)

// newUserMutation creates new mutation for the User entity.
func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
	m := &UserMutation{
		config:        c,
		op:            op,
		typ:           TypeUser,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withUserID sets the ID field of the mutation.
func withUserID(id int) userOption {
	return func(m *UserMutation) {
		var (
			err   error
			once  sync.Once
			value *User
		)
		m.oldValue = func(ctx context.Context) (*User, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().User.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withUser sets the old User of the mutation.
func withUser(node *User) userOption {
	return func(m *UserMutation) {
		m.oldValue = func(context.Context) (*User, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m UserMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m UserMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of User entities.
func (m *UserMutation) SetID(id int) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *UserMutation) ID() (id int, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *UserMutation) IDs(ctx context.Context) ([]int, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetEmail sets the "email" field.
func (m *UserMutation) SetEmail(s string) {
	m.email = &s
}

// Email returns the value of the "email" field in the mutation.
func (m *UserMutation) Email() (r string, exists bool) {
	v := m.email
	if v == nil {
		return
	}
	return *v, true
}

// OldEmail returns the old "email" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldEmail is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldEmail requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldEmail: %w", err)
	}
	return oldValue.Email, nil
}

// ResetEmail resets all changes to the "email" field.
func (m *UserMutation) ResetEmail() {
	m.email = nil
}

// SetPassword sets the "password" field.
func (m *UserMutation) SetPassword(b []byte) {
	m.password = &b
}

// Password returns the value of the "password" field in the mutation.
func (m *UserMutation) Password() (r []byte, exists bool) {
	v := m.password
	if v == nil {
		return
	}
	return *v, true
}

// OldPassword returns the old "password" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldPassword(ctx context.Context) (v []byte, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPassword is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPassword requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPassword: %w", err)
	}
	return oldValue.Password, nil
}

// ResetPassword resets all changes to the "password" field.
func (m *UserMutation) ResetPassword() {
	m.password = nil
}

// SetFirstName sets the "firstName" field.
func (m *UserMutation) SetFirstName(s string) {
	m.firstName = &s
}

// FirstName returns the value of the "firstName" field in the mutation.
func (m *UserMutation) FirstName() (r string, exists bool) {
	v := m.firstName
	if v == nil {
		return
	}
	return *v, true
}

// OldFirstName returns the old "firstName" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldFirstName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFirstName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFirstName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFirstName: %w", err)
	}
	return oldValue.FirstName, nil
}

// ClearFirstName clears the value of the "firstName" field.
func (m *UserMutation) ClearFirstName() {
	m.firstName = nil
	m.clearedFields[user.FieldFirstName] = struct{}{}
}

// FirstNameCleared returns if the "firstName" field was cleared in this mutation.
func (m *UserMutation) FirstNameCleared() bool {
	_, ok := m.clearedFields[user.FieldFirstName]
	return ok
}

// ResetFirstName resets all changes to the "firstName" field.
func (m *UserMutation) ResetFirstName() {
	m.firstName = nil
	delete(m.clearedFields, user.FieldFirstName)
}

// SetLastName sets the "lastName" field.
func (m *UserMutation) SetLastName(s string) {
	m.lastName = &s
}

// LastName returns the value of the "lastName" field in the mutation.
func (m *UserMutation) LastName() (r string, exists bool) {
	v := m.lastName
	if v == nil {
		return
	}
	return *v, true
}

// OldLastName returns the old "lastName" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldLastName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLastName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLastName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLastName: %w", err)
	}
	return oldValue.LastName, nil
}

// ClearLastName clears the value of the "lastName" field.
func (m *UserMutation) ClearLastName() {
	m.lastName = nil
	m.clearedFields[user.FieldLastName] = struct{}{}
}

// LastNameCleared returns if the "lastName" field was cleared in this mutation.
func (m *UserMutation) LastNameCleared() bool {
	_, ok := m.clearedFields[user.FieldLastName]
	return ok
}

// ResetLastName resets all changes to the "lastName" field.
func (m *UserMutation) ResetLastName() {
	m.lastName = nil
	delete(m.clearedFields, user.FieldLastName)
}

// Where appends a list predicates to the UserMutation builder.
func (m *UserMutation) Where(ps ...predicate.User) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the UserMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.User, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *UserMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *UserMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (User).
func (m *UserMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UserMutation) Fields() []string {
	fields := make([]string, 0, 4)
	if m.email != nil {
		fields = append(fields, user.FieldEmail)
	}
	if m.password != nil {
		fields = append(fields, user.FieldPassword)
	}
	if m.firstName != nil {
		fields = append(fields, user.FieldFirstName)
	}
	if m.lastName != nil {
		fields = append(fields, user.FieldLastName)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *UserMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case user.FieldEmail:
		return m.Email()
	case user.FieldPassword:
		return m.Password()
	case user.FieldFirstName:
		return m.FirstName()
	case user.FieldLastName:
		return m.LastName()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case user.FieldEmail:
		return m.OldEmail(ctx)
	case user.FieldPassword:
		return m.OldPassword(ctx)
	case user.FieldFirstName:
		return m.OldFirstName(ctx)
	case user.FieldLastName:
		return m.OldLastName(ctx)
	}
	return nil, fmt.Errorf("unknown User field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UserMutation) SetField(name string, value ent.Value) error {
	switch name {
	case user.FieldEmail:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEmail(v)
		return nil
	case user.FieldPassword:
		v, ok := value.([]byte)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPassword(v)
		return nil
	case user.FieldFirstName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFirstName(v)
		return nil
	case user.FieldLastName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastName(v)
		return nil
	}
	return fmt.Errorf("unknown User field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserMutation) AddedFields() []string {
	return nil
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UserMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown User numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(user.FieldFirstName) {
		fields = append(fields, user.FieldFirstName)
	}
	if m.FieldCleared(user.FieldLastName) {
		fields = append(fields, user.FieldLastName)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *UserMutation) ClearField(name string) error {
	switch name {
	case user.FieldFirstName:
		m.ClearFirstName()
		return nil
	case user.FieldLastName:
		m.ClearLastName()
		return nil
	}
	return fmt.Errorf("unknown User nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *UserMutation) ResetField(name string) error {
	switch name {
	case user.FieldEmail:
		m.ResetEmail()
		return nil
	case user.FieldPassword:
		m.ResetPassword()
		return nil
	case user.FieldFirstName:
		m.ResetFirstName()
		return nil
	case user.FieldLastName:
		m.ResetLastName()
		return nil
	}
	return fmt.Errorf("unknown User field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UserMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserMutation) EdgeCleared(name string) bool {
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *UserMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown User unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *UserMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown User edge %s", name)
}

// WeatherMutation represents an operation that mutates the Weather nodes in the graph.
type WeatherMutation struct {
	config
	op                     Op
	typ                    string
	id                     *int64
	temperature            *float64
	addtemperature         *float64
	humidity               *float64
	addhumidity            *float64
	windSpeed              *float64
	addwindSpeed           *float64
	weatherCondition       *weather.WeatherCondition
	precipitationAmount    *float64
	addprecipitationAmount *float64
	measurementDateTime    *time.Time
	clearedFields          map[string]struct{}
	region                 *int64
	clearedregion          bool
	forecast               map[int64]struct{}
	removedforecast        map[int64]struct{}
	clearedforecast        bool
	done                   bool
	oldValue               func(context.Context) (*Weather, error)
	predicates             []predicate.Weather
}

var _ ent.Mutation = (*WeatherMutation)(nil)

// weatherOption allows management of the mutation configuration using functional options.
type weatherOption func(*WeatherMutation)

// newWeatherMutation creates new mutation for the Weather entity.
func newWeatherMutation(c config, op Op, opts ...weatherOption) *WeatherMutation {
	m := &WeatherMutation{
		config:        c,
		op:            op,
		typ:           TypeWeather,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withWeatherID sets the ID field of the mutation.
func withWeatherID(id int64) weatherOption {
	return func(m *WeatherMutation) {
		var (
			err   error
			once  sync.Once
			value *Weather
		)
		m.oldValue = func(ctx context.Context) (*Weather, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Weather.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withWeather sets the old Weather of the mutation.
func withWeather(node *Weather) weatherOption {
	return func(m *WeatherMutation) {
		m.oldValue = func(context.Context) (*Weather, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m WeatherMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m WeatherMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Weather entities.
func (m *WeatherMutation) SetID(id int64) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *WeatherMutation) ID() (id int64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *WeatherMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Weather.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetTemperature sets the "temperature" field.
func (m *WeatherMutation) SetTemperature(f float64) {
	m.temperature = &f
	m.addtemperature = nil
}

// Temperature returns the value of the "temperature" field in the mutation.
func (m *WeatherMutation) Temperature() (r float64, exists bool) {
	v := m.temperature
	if v == nil {
		return
	}
	return *v, true
}

// OldTemperature returns the old "temperature" field's value of the Weather entity.
// If the Weather object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WeatherMutation) OldTemperature(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTemperature is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTemperature requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTemperature: %w", err)
	}
	return oldValue.Temperature, nil
}

// AddTemperature adds f to the "temperature" field.
func (m *WeatherMutation) AddTemperature(f float64) {
	if m.addtemperature != nil {
		*m.addtemperature += f
	} else {
		m.addtemperature = &f
	}
}

// AddedTemperature returns the value that was added to the "temperature" field in this mutation.
func (m *WeatherMutation) AddedTemperature() (r float64, exists bool) {
	v := m.addtemperature
	if v == nil {
		return
	}
	return *v, true
}

// ResetTemperature resets all changes to the "temperature" field.
func (m *WeatherMutation) ResetTemperature() {
	m.temperature = nil
	m.addtemperature = nil
}

// SetHumidity sets the "humidity" field.
func (m *WeatherMutation) SetHumidity(f float64) {
	m.humidity = &f
	m.addhumidity = nil
}

// Humidity returns the value of the "humidity" field in the mutation.
func (m *WeatherMutation) Humidity() (r float64, exists bool) {
	v := m.humidity
	if v == nil {
		return
	}
	return *v, true
}

// OldHumidity returns the old "humidity" field's value of the Weather entity.
// If the Weather object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WeatherMutation) OldHumidity(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldHumidity is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldHumidity requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldHumidity: %w", err)
	}
	return oldValue.Humidity, nil
}

// AddHumidity adds f to the "humidity" field.
func (m *WeatherMutation) AddHumidity(f float64) {
	if m.addhumidity != nil {
		*m.addhumidity += f
	} else {
		m.addhumidity = &f
	}
}

// AddedHumidity returns the value that was added to the "humidity" field in this mutation.
func (m *WeatherMutation) AddedHumidity() (r float64, exists bool) {
	v := m.addhumidity
	if v == nil {
		return
	}
	return *v, true
}

// ResetHumidity resets all changes to the "humidity" field.
func (m *WeatherMutation) ResetHumidity() {
	m.humidity = nil
	m.addhumidity = nil
}

// SetWindSpeed sets the "windSpeed" field.
func (m *WeatherMutation) SetWindSpeed(f float64) {
	m.windSpeed = &f
	m.addwindSpeed = nil
}

// WindSpeed returns the value of the "windSpeed" field in the mutation.
func (m *WeatherMutation) WindSpeed() (r float64, exists bool) {
	v := m.windSpeed
	if v == nil {
		return
	}
	return *v, true
}

// OldWindSpeed returns the old "windSpeed" field's value of the Weather entity.
// If the Weather object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WeatherMutation) OldWindSpeed(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWindSpeed is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWindSpeed requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWindSpeed: %w", err)
	}
	return oldValue.WindSpeed, nil
}

// AddWindSpeed adds f to the "windSpeed" field.
func (m *WeatherMutation) AddWindSpeed(f float64) {
	if m.addwindSpeed != nil {
		*m.addwindSpeed += f
	} else {
		m.addwindSpeed = &f
	}
}

// AddedWindSpeed returns the value that was added to the "windSpeed" field in this mutation.
func (m *WeatherMutation) AddedWindSpeed() (r float64, exists bool) {
	v := m.addwindSpeed
	if v == nil {
		return
	}
	return *v, true
}

// ResetWindSpeed resets all changes to the "windSpeed" field.
func (m *WeatherMutation) ResetWindSpeed() {
	m.windSpeed = nil
	m.addwindSpeed = nil
}

// SetWeatherCondition sets the "weatherCondition" field.
func (m *WeatherMutation) SetWeatherCondition(wc weather.WeatherCondition) {
	m.weatherCondition = &wc
}

// WeatherCondition returns the value of the "weatherCondition" field in the mutation.
func (m *WeatherMutation) WeatherCondition() (r weather.WeatherCondition, exists bool) {
	v := m.weatherCondition
	if v == nil {
		return
	}
	return *v, true
}

// OldWeatherCondition returns the old "weatherCondition" field's value of the Weather entity.
// If the Weather object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WeatherMutation) OldWeatherCondition(ctx context.Context) (v weather.WeatherCondition, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWeatherCondition is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWeatherCondition requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWeatherCondition: %w", err)
	}
	return oldValue.WeatherCondition, nil
}

// ResetWeatherCondition resets all changes to the "weatherCondition" field.
func (m *WeatherMutation) ResetWeatherCondition() {
	m.weatherCondition = nil
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (m *WeatherMutation) SetPrecipitationAmount(f float64) {
	m.precipitationAmount = &f
	m.addprecipitationAmount = nil
}

// PrecipitationAmount returns the value of the "precipitationAmount" field in the mutation.
func (m *WeatherMutation) PrecipitationAmount() (r float64, exists bool) {
	v := m.precipitationAmount
	if v == nil {
		return
	}
	return *v, true
}

// OldPrecipitationAmount returns the old "precipitationAmount" field's value of the Weather entity.
// If the Weather object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WeatherMutation) OldPrecipitationAmount(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPrecipitationAmount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPrecipitationAmount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPrecipitationAmount: %w", err)
	}
	return oldValue.PrecipitationAmount, nil
}

// AddPrecipitationAmount adds f to the "precipitationAmount" field.
func (m *WeatherMutation) AddPrecipitationAmount(f float64) {
	if m.addprecipitationAmount != nil {
		*m.addprecipitationAmount += f
	} else {
		m.addprecipitationAmount = &f
	}
}

// AddedPrecipitationAmount returns the value that was added to the "precipitationAmount" field in this mutation.
func (m *WeatherMutation) AddedPrecipitationAmount() (r float64, exists bool) {
	v := m.addprecipitationAmount
	if v == nil {
		return
	}
	return *v, true
}

// ResetPrecipitationAmount resets all changes to the "precipitationAmount" field.
func (m *WeatherMutation) ResetPrecipitationAmount() {
	m.precipitationAmount = nil
	m.addprecipitationAmount = nil
}

// SetMeasurementDateTime sets the "measurementDateTime" field.
func (m *WeatherMutation) SetMeasurementDateTime(t time.Time) {
	m.measurementDateTime = &t
}

// MeasurementDateTime returns the value of the "measurementDateTime" field in the mutation.
func (m *WeatherMutation) MeasurementDateTime() (r time.Time, exists bool) {
	v := m.measurementDateTime
	if v == nil {
		return
	}
	return *v, true
}

// OldMeasurementDateTime returns the old "measurementDateTime" field's value of the Weather entity.
// If the Weather object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *WeatherMutation) OldMeasurementDateTime(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldMeasurementDateTime is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldMeasurementDateTime requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldMeasurementDateTime: %w", err)
	}
	return oldValue.MeasurementDateTime, nil
}

// ResetMeasurementDateTime resets all changes to the "measurementDateTime" field.
func (m *WeatherMutation) ResetMeasurementDateTime() {
	m.measurementDateTime = nil
}

// SetRegionID sets the "region" edge to the Region entity by id.
func (m *WeatherMutation) SetRegionID(id int64) {
	m.region = &id
}

// ClearRegion clears the "region" edge to the Region entity.
func (m *WeatherMutation) ClearRegion() {
	m.clearedregion = true
}

// RegionCleared reports if the "region" edge to the Region entity was cleared.
func (m *WeatherMutation) RegionCleared() bool {
	return m.clearedregion
}

// RegionID returns the "region" edge ID in the mutation.
func (m *WeatherMutation) RegionID() (id int64, exists bool) {
	if m.region != nil {
		return *m.region, true
	}
	return
}

// RegionIDs returns the "region" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// RegionID instead. It exists only for internal usage by the builders.
func (m *WeatherMutation) RegionIDs() (ids []int64) {
	if id := m.region; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetRegion resets all changes to the "region" edge.
func (m *WeatherMutation) ResetRegion() {
	m.region = nil
	m.clearedregion = false
}

// AddForecastIDs adds the "forecast" edge to the Forecast entity by ids.
func (m *WeatherMutation) AddForecastIDs(ids ...int64) {
	if m.forecast == nil {
		m.forecast = make(map[int64]struct{})
	}
	for i := range ids {
		m.forecast[ids[i]] = struct{}{}
	}
}

// ClearForecast clears the "forecast" edge to the Forecast entity.
func (m *WeatherMutation) ClearForecast() {
	m.clearedforecast = true
}

// ForecastCleared reports if the "forecast" edge to the Forecast entity was cleared.
func (m *WeatherMutation) ForecastCleared() bool {
	return m.clearedforecast
}

// RemoveForecastIDs removes the "forecast" edge to the Forecast entity by IDs.
func (m *WeatherMutation) RemoveForecastIDs(ids ...int64) {
	if m.removedforecast == nil {
		m.removedforecast = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.forecast, ids[i])
		m.removedforecast[ids[i]] = struct{}{}
	}
}

// RemovedForecast returns the removed IDs of the "forecast" edge to the Forecast entity.
func (m *WeatherMutation) RemovedForecastIDs() (ids []int64) {
	for id := range m.removedforecast {
		ids = append(ids, id)
	}
	return
}

// ForecastIDs returns the "forecast" edge IDs in the mutation.
func (m *WeatherMutation) ForecastIDs() (ids []int64) {
	for id := range m.forecast {
		ids = append(ids, id)
	}
	return
}

// ResetForecast resets all changes to the "forecast" edge.
func (m *WeatherMutation) ResetForecast() {
	m.forecast = nil
	m.clearedforecast = false
	m.removedforecast = nil
}

// Where appends a list predicates to the WeatherMutation builder.
func (m *WeatherMutation) Where(ps ...predicate.Weather) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the WeatherMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *WeatherMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.Weather, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *WeatherMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *WeatherMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (Weather).
func (m *WeatherMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *WeatherMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.temperature != nil {
		fields = append(fields, weather.FieldTemperature)
	}
	if m.humidity != nil {
		fields = append(fields, weather.FieldHumidity)
	}
	if m.windSpeed != nil {
		fields = append(fields, weather.FieldWindSpeed)
	}
	if m.weatherCondition != nil {
		fields = append(fields, weather.FieldWeatherCondition)
	}
	if m.precipitationAmount != nil {
		fields = append(fields, weather.FieldPrecipitationAmount)
	}
	if m.measurementDateTime != nil {
		fields = append(fields, weather.FieldMeasurementDateTime)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *WeatherMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case weather.FieldTemperature:
		return m.Temperature()
	case weather.FieldHumidity:
		return m.Humidity()
	case weather.FieldWindSpeed:
		return m.WindSpeed()
	case weather.FieldWeatherCondition:
		return m.WeatherCondition()
	case weather.FieldPrecipitationAmount:
		return m.PrecipitationAmount()
	case weather.FieldMeasurementDateTime:
		return m.MeasurementDateTime()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *WeatherMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case weather.FieldTemperature:
		return m.OldTemperature(ctx)
	case weather.FieldHumidity:
		return m.OldHumidity(ctx)
	case weather.FieldWindSpeed:
		return m.OldWindSpeed(ctx)
	case weather.FieldWeatherCondition:
		return m.OldWeatherCondition(ctx)
	case weather.FieldPrecipitationAmount:
		return m.OldPrecipitationAmount(ctx)
	case weather.FieldMeasurementDateTime:
		return m.OldMeasurementDateTime(ctx)
	}
	return nil, fmt.Errorf("unknown Weather field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *WeatherMutation) SetField(name string, value ent.Value) error {
	switch name {
	case weather.FieldTemperature:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTemperature(v)
		return nil
	case weather.FieldHumidity:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetHumidity(v)
		return nil
	case weather.FieldWindSpeed:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWindSpeed(v)
		return nil
	case weather.FieldWeatherCondition:
		v, ok := value.(weather.WeatherCondition)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWeatherCondition(v)
		return nil
	case weather.FieldPrecipitationAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPrecipitationAmount(v)
		return nil
	case weather.FieldMeasurementDateTime:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMeasurementDateTime(v)
		return nil
	}
	return fmt.Errorf("unknown Weather field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *WeatherMutation) AddedFields() []string {
	var fields []string
	if m.addtemperature != nil {
		fields = append(fields, weather.FieldTemperature)
	}
	if m.addhumidity != nil {
		fields = append(fields, weather.FieldHumidity)
	}
	if m.addwindSpeed != nil {
		fields = append(fields, weather.FieldWindSpeed)
	}
	if m.addprecipitationAmount != nil {
		fields = append(fields, weather.FieldPrecipitationAmount)
	}
	return fields
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *WeatherMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case weather.FieldTemperature:
		return m.AddedTemperature()
	case weather.FieldHumidity:
		return m.AddedHumidity()
	case weather.FieldWindSpeed:
		return m.AddedWindSpeed()
	case weather.FieldPrecipitationAmount:
		return m.AddedPrecipitationAmount()
	}
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *WeatherMutation) AddField(name string, value ent.Value) error {
	switch name {
	case weather.FieldTemperature:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddTemperature(v)
		return nil
	case weather.FieldHumidity:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddHumidity(v)
		return nil
	case weather.FieldWindSpeed:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddWindSpeed(v)
		return nil
	case weather.FieldPrecipitationAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPrecipitationAmount(v)
		return nil
	}
	return fmt.Errorf("unknown Weather numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *WeatherMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *WeatherMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *WeatherMutation) ClearField(name string) error {
	return fmt.Errorf("unknown Weather nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *WeatherMutation) ResetField(name string) error {
	switch name {
	case weather.FieldTemperature:
		m.ResetTemperature()
		return nil
	case weather.FieldHumidity:
		m.ResetHumidity()
		return nil
	case weather.FieldWindSpeed:
		m.ResetWindSpeed()
		return nil
	case weather.FieldWeatherCondition:
		m.ResetWeatherCondition()
		return nil
	case weather.FieldPrecipitationAmount:
		m.ResetPrecipitationAmount()
		return nil
	case weather.FieldMeasurementDateTime:
		m.ResetMeasurementDateTime()
		return nil
	}
	return fmt.Errorf("unknown Weather field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *WeatherMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.region != nil {
		edges = append(edges, weather.EdgeRegion)
	}
	if m.forecast != nil {
		edges = append(edges, weather.EdgeForecast)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *WeatherMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case weather.EdgeRegion:
		if id := m.region; id != nil {
			return []ent.Value{*id}
		}
	case weather.EdgeForecast:
		ids := make([]ent.Value, 0, len(m.forecast))
		for id := range m.forecast {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *WeatherMutation) RemovedEdges() []string {
	edges := make([]string, 0, 2)
	if m.removedforecast != nil {
		edges = append(edges, weather.EdgeForecast)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *WeatherMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case weather.EdgeForecast:
		ids := make([]ent.Value, 0, len(m.removedforecast))
		for id := range m.removedforecast {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *WeatherMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedregion {
		edges = append(edges, weather.EdgeRegion)
	}
	if m.clearedforecast {
		edges = append(edges, weather.EdgeForecast)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *WeatherMutation) EdgeCleared(name string) bool {
	switch name {
	case weather.EdgeRegion:
		return m.clearedregion
	case weather.EdgeForecast:
		return m.clearedforecast
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *WeatherMutation) ClearEdge(name string) error {
	switch name {
	case weather.EdgeRegion:
		m.ClearRegion()
		return nil
	}
	return fmt.Errorf("unknown Weather unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *WeatherMutation) ResetEdge(name string) error {
	switch name {
	case weather.EdgeRegion:
		m.ResetRegion()
		return nil
	case weather.EdgeForecast:
		m.ResetForecast()
		return nil
	}
	return fmt.Errorf("unknown Weather edge %s", name)
}
